package com.dingwei.superiordiary.adapter.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dingwei.superiordiary.R;
import com.dingwei.superiordiary.app.MyApplication;
import com.dingwei.superiordiary.bean.BrowseHistoryBean;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.lihao.baselibrary.base.BaseActivity;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by lihao on 2018/1/8.
 */

public class BrowseHistoryAdapter extends RecyclerArrayAdapter<BrowseHistoryBean.DataBean> {


    public interface xxInterFace {
        void  delete(int position);
    }
    private xxInterFace xxInterfaceListener;
        public void xxInterfaceListener(xxInterFace listener){
            xxInterfaceListener = listener;

        }



    public BrowseHistoryAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new BrowseHistoryHolder(parent);
    }

    class BrowseHistoryHolder extends BaseViewHolder<BrowseHistoryBean.DataBean> {


        @Bind(R.id.tv_day)
        TextView tvDay;
        @Bind(R.id.img_delete)
        ImageView imgDelete;
        @Bind(R.id.img)
        ImageView img;
        @Bind(R.id.tv_content)
        TextView tvContent;
        @Bind(R.id.tv_look)
        TextView tvLook;
        @Bind(R.id.tv_like)
        TextView tvLike;
        @Bind(R.id.tv_collect)
        TextView tvCollect;
        @Bind(R.id.tv_month)
        TextView tvMonth;

        public BrowseHistoryHolder(ViewGroup parent) {
            super(parent, R.layout.item_browse_history);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void setData(BrowseHistoryBean.DataBean data) {
            super.setData(data);
            tvDay.setText(data.day);
            tvMonth.setText(data.month);
            tvContent.setText(data.name);
            tvLike.setText(data.likes+"");
            tvLook.setText(data.viewed+"");
            tvCollect.setText(data.collection+"");
            Glide.with(BaseActivity.context)
                    .load(data.icon)
                    .apply(MyApplication.options)
                    .into(img);

            imgDelete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (xxInterfaceListener!=null){
                        xxInterfaceListener.delete(getDataPosition());
                    }
                }
            });

        }
    }
}
